<template lang="html">
  <div class="">
    <div
    tag="div"
    @click = "goBack"
    class="header-abs"
    v-show = "showABS"
    >
      <span class="iconfont banner-icon ">
        &#xe608;
      </span>
    </div>
    <div
    class="header-fixed"
    v-show = "!showABS"
    :style="opacityStyle"
    >
      <router-link to="/">
        <div class="header-right">
            <span class="iconfont back-icon">&#xe608;</span>
        </div>
      </router-link>
      <div class="">
        景点详情
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'DetailHeader',
  data () {
    return {
      showABS: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      console.log(1);
      const top = document.documentElement.scrollTop
      if (top > 1 && top < 140) {
        const opacity = top/140
        this.showABS = false
        this.opacityStyle = {
          opacity
        }
        console.log(opacity);
      }
      if(top<=1)
      {
        this.showABS = true
      }
    },
    goBack () {
      this.$router.goBack(-1)
    }
  },
  activated () {
    console.log(1);
    window.addEventListener('scroll', this.handleScroll)
  },
  deactivated () {
    console.log(1);
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>

<style lang="stylus" scoped>
@import '~styles/varibles.styl';
  .header-abs
    position: absolute
    left: .2rem
    top: .2rem
    width: .7rem
    height: .7rem
    border-radius: .35rem
    text-align: center;
    line-height: .7rem
    background: rgba(0, 0, 0, 0.6)
    .banner-icon
      color: #fff
  .header-fixed
    z-index: 99;
    position: fixed
    top: 0
    left: 0
    right: 0
    height: $headerHeight
    padding-right: .4rem;
    line-height: $headerHeight
    text-align: center
    color: #fff
    font-size: .36rem
    background: $bgColor
    .header-right
      margin-left: .2rem
      float: left
      display: inline-block
      .iconfont
        font-size: .45rem
        color: #fff
</style>
